home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form ChangePrinter
- Caption = "Changing the Default Printer"
- ClientHeight = 2370
- ClientLeft = 3330
- ClientTop = 4155
- ClientWidth = 4470
- Height = 2775
- Left = 3270
- LinkTopic = "Form2"
- ScaleHeight = 2370
- ScaleWidth = 4470
- Top = 3810
- Width = 4590
- Begin CommandButton Command2
- Caption = "PrintForm"
- Height = 495
- Left = 300
- TabIndex = 3
- Top = 1500
- Width = 1335
- End
- Begin ComboBox Combo1
- Height = 300
- Left = 120
- Style = 2 'Dropdown List
- TabIndex = 1
- Top = 540
- Width = 4155
- End
- Begin CommandButton Command1
- Caption = "Ok"
- Height = 495
- Left = 2880
- TabIndex = 0
- Top = 1500
- Width = 1395
- End
- Begin Label Label1
- Caption = "Default Printer"
- Height = 255
- Left = 120
- TabIndex = 2
- Top = 180
- Width = 2955
- End
- ' ------------------------------------------------------------------------
- ' changepr.frm -- Top 9 API Tricks
- ' Copyright (C) 1993 Desaware
- ' You have a royalty-free right to use, modify, reproduce and distribute
- ' this file (and/or any modified version) in any way you find useful,
- ' provided that you agree that Desaware has no
- ' warranty, obligation or liability for its contents.
- ' ------------------------------------------------------------------------
- Option Explicit
- Sub Combo1_Click ()
- Dim di%, dl&
- Dim newpr$
- newpr$ = Combo1.Text
- If Len(newpr$) > 0 Then
- di% = WriteProfileString("windows", "device", newpr$)
- ' Notify all applications that printer has changed
- dl& = SendMessageByString(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
- End If
- End Sub
- Sub Command1_Click ()
- Unload Me
- End Sub
- Sub Command2_Click ()
- Me.PrintForm
- End Sub
- Sub Form_Load ()
- Dim pr$
- Dim di%, x%
- Dim defpr$
- Dim thispr$
- pr$ = String$(2048, 0) ' Initialize the string
- defpr$ = String$(256, 0)
- di% = GetProfileString("windows", "device", "", defpr$, 2047)
- defpr$ = NullTermToVBString$(defpr$)
- ' Note use of byval to pass null
- di% = GetProfileString("devices", ByVal 0&, "", pr$, 2047)
- x% = 0
- Do
- thispr$ = ParseAnyString(pr$, x%, Chr$(0))
- If thispr$ <> "" Then
- Combo1.AddItem GetRealPr$(thispr$)
- End If
- x% = x% + 1
- Loop While thispr$ <> ""
- ' Select the current one
- For x% = 0 To Combo1.ListCount - 1
- If UCase$(Combo1.List(x%)) = UCase$(defpr$) Then
- Combo1.ListIndex = x%
- Exit For
- End If
- Next x%
- End Sub
- Function GetRealPr$ (thispr$)
- Dim newpr$
- Dim di%
- newpr$ = String$(255, 0)
- di% = GetProfileString("devices", thispr$, "", newpr$, 254)
- GetRealPr$ = thispr$ & "," & NullTermToVBString(newpr$)
- End Function
-